<!-- 导师业务经费发放管理 -->
<template>
    <div class="con">
        <div>
            <ConditionCard shadow="never" body-style="padding: 24px 24px 6px 24px;" @search="onSubmit(true)" @reset="reset">
                <el-form ref="queryForm" label-suffix="：" :model="queryForm" label-position="right" label-width="120px">
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('fundDistribution.year')">
                                <DictSelect v-model="queryForm.year" :data="options.year" filterable :clearable="false" v-clearreadonly></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.college')">
                              <DictSelect
                                v-model="queryForm.faculty"
                                clearable
                                filterable
                                :placeholder="$t('common.text.all')"
                                :data="options.academyId"
                                v-clearreadonly
                              >
                              </DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                          <el-form-item :label="$t('fundQueryPage.specialPlan')">
                            <DictSelect
                              v-model="queryForm.specialPlan"
                              filterable
                              :data="options.specialPlan"
                              v-clearreadonly>
                            </DictSelect>
                          </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </ConditionCard>
            <el-card shadow="never" body-style="padding: 24px;">
              <div class="edu-opertion-bar">
                  <div class="float-left">
                    <h1 class="condition-title">{{$t('fundQueryPage.titleLabel')}}</h1>
                    <!-- <KeywordInput v-model="queryForm.ruleName" :placeholder="$t('achievementApply.rulePlaceholder')" @enter="search"></KeywordInput> -->
                  </div>
                  <div class="float-right">
                      <el-button @click="exoprtAllFunc" type="primary">{{$t('fundQueryPage.exportAll')}}</el-button>
                      <el-button @click="exportExcelFunc" type="primary">{{$t('fundQueryPage.exportExcel')}}</el-button>
                  </div>
              </div>
              <edu-table ref="tables" :url="tableApi" :selection="false" :orderFixed="true">
                  <el-table-column min-width="90" :label="$t('fundQueryPage.mentorAccount')" prop="cardNo" show-overflow-tooltip></el-table-column>
                  <el-table-column min-width="90" :label="$t('fundDistribution.tutorNum')" prop="tutorNo" show-overflow-tooltip></el-table-column>
                  <el-table-column min-width="90" :label="$t('fundQueryPage.tutorName')" prop="tutorName" show-overflow-tooltip></el-table-column>
                  <el-table-column min-width="80" :label="`${(yearNum-2)}级${$t('fundQueryPage.doctor')}`" prop="firstPhD" show-overflow-tooltip></el-table-column>
                  <el-table-column min-width="80" :label="`${yearNum-1}级${$t('fundQueryPage.doctor')}`" prop="secondPhD" show-overflow-tooltip></el-table-column>
                  <el-table-column min-width="80" :label="`${(yearNum-2)}级${$t('fundQueryPage.master')}`" prop="firstMaster" show-overflow-tooltip></el-table-column>
                  <el-table-column min-width="80" :label="`${yearNum-1}级${$t('fundQueryPage.master')}`" prop="secondMaster" show-overflow-tooltip></el-table-column>
                  <el-table-column min-width="80" :label="$t('fundQueryPage.amount')" prop="amount" show-overflow-tooltip></el-table-column>
                  <el-table-column min-width="100" :label="$t('message.remark')" prop="remark" show-overflow-tooltip></el-table-column>
              </edu-table>
            </el-card>
        </div>
    </div>
</template>

<script>
import { fundsQueryList, queryPageExportExcel, queryPageExportAll } from "common/src/api/fundManagement/standardSetting";
import commonMixins from 'common/src/views/practiceManagement/commonMixins';
import examinationStudentsApi from "common/src/api/welcomeService/examinationStudents";//导出
import moment from 'moment';
export default {
    mixins: [commonMixins],
    data() {
        return {
            tableApi: fundsQueryList,
            queryForm: {
              year: '',
              faculty: '',
              specialPlan: ''
            },
            options: {
              year: [], // 年度
              academyId: [], // 学院
              specialPlan: [] // 专项计划
            },
            yearNum: 19,
        };
    },
    computed: {

    },
    created() {
    },
    mounted() {
      let currentYear = moment().year();
      let maxYear = currentYear + 2;
      // 获取数据字典数据
      let param = {
        X_YX: 'academyId', // 学院
        X_ZXJH: 'specialPlan', // 专项计划
      };
      this.initOptions(param);
      for (let i = 0; i <= 50; i++) {
        let showYear = maxYear - i;
        this.options.year.push(
          {
            label: showYear,
            value: showYear
          }
        );
      }
      this.queryForm.year = currentYear;
      this.yearNum = Number((currentYear+'').substr(2,2));
      this.onSubmit(true);
    },
    methods: {
      onSubmit(refresh) { // 筛选
        if (refresh) {
          this.$refs.tables.pageNum = 1;
        }
        this.yearNum = Number((this.queryForm.year+'').substr(2,2));
        this.$refs.tables.search(this.queryForm);
      },
      reset() {  // 重置
        for (const key in this.queryForm) {
          this.queryForm[key] = '';
        }
        this.queryForm.year = moment().year();
        this.onSubmit(true);
      },
      search() { // 搜索
        this.queryForm.ruleName = this.queryForm.ruleName.trim();
        this.onSubmit(true);
      },
      // 导出业务经费汇总表
      exoprtAllFunc() {
        let param = this.queryForm;
        let title = this.queryForm.year + '年研究生导师业务费发放总表';
        if (this.queryForm.specialPlan == '10') {
          title = this.queryForm.year + '年住院医师导师经费发放汇总表';
        }
        queryPageExportAll(param, title);
      },
      // 导出excel
      exportExcelFunc() {
        let loading = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(255, 255, 255, .48)"
        });
        let param = this.queryForm;
        queryPageExportExcel(param).then(res => {
          if (res.code == 200) {
            this.delayRequest(res.data.key, loading);
          } else {
            loading.close();
          }
        });
      },
      async delayRequest(key, loading) {
        await new Promise(resolve => setTimeout(resolve, 5000));
        examinationStudentsApi.getReportStatus(key).then(res => {
            if (res.code == 200 && res.data.status) {
              let path = examinationStudentsApi.exportUrl + res.data.path;
              window.location.href = path;
              loading.close();
            } else {
              this.delayRequest(key, loading);
            }
          })
          .catch(ex => {
            this.$message({
              type: "error",
              message: "导出失败"
            });
          });
      },
    }
};
</script>

<style scoped lang="scss">
</style>

